
#include "OSScheduler.h"
#include <iostream>


OSScheduler::OSScheduler()
	//m_curThreadPhase(0)
{}

/*OSScheduler::OSScheduler(int quanta,threadsTable& tT,map<string, Worker>* workers,Mailer* mailer):
	m_curThreadPhase(0),m_contex_switch_count(0),m_quanta_count(0),m_msg_passed_count(0),m_phase_count(0)
{
	m_quanta = quanta;
	m_tT = &tT;
	m_workers = workers;
	m_mailer = mailer;
}
*/
//bool OSScheduler::checkThreadBlocked()
//{
//	bool result = false;
//
//	if (m_curThread != NULL)
//	{
//		// Check if the current thread's phase has changed from the last check
//		int readThreadPhase = m_curThread->getPhase();
//
//		// Check if the thread is still in the same phase
//		if (m_curThreadPhase == readThreadPhase)
//			result = true;
//
//		m_curThreadPhase = readThreadPhase;
//	}
//
//	return result;
//}
//
//void OSScheduler::notifyThreadChange(OSThread *newThread)
//{
//	m_curThread = newThread;
//
//	// Save the thread's current phase
//	m_curThreadPhase = m_curThread->getPhase();
//}


/*void* OSScheduler::getThreadsTable(){
	return m_tT;
}*/

/*int OSScheduler::getQuanta(){

	return m_quanta;
}*/

/*map<string, Worker>* OSScheduler::getWorkers(){
	 return m_workers;
}*/



void OSScheduler::init(){

}

void OSScheduler::nextWorker(){

}

/* increment the contex switches count by 1 */
/*void OSScheduler::incCScount(){
	//m_contex_switch_count++;
}

void OSScheduler::incMsgPass(){
	//m_msg_passed_count++;
}

void OSScheduler::incQuantaCount(){
	//m_quanta_count++;
}*/


bool OSScheduler::isStable(){

/*	int current_phases = 0;

	map<string, Worker>::iterator iter;
	map<string, Worker>* workers = getWorkers();
	for(iter = workers->begin() ; iter != workers->end() ;++iter){
		current_phases =+ iter->second.getPhase() ;
	}

	if ((m_phase_count == current_phases) & (current_phases != 0)) {
			return true;
	}

	m_phase_count = current_phases;
	return false;*/

}

/* prints summary :
	 *
	 * - number of context switches between threads.
	 * - sum of message quanta given to all worker threads from last initialization.
	 * - actual number of messages passed from last initialization.
	 * - the thread table .
	 */
void OSScheduler::printSum(){
/*	cout << " SUMMARY of scheduling iteration : \n" ;
	cout << " - number of context switches :\t" << m_contex_switch_count <<"\n";
	cout << " - message quanta given :\t" << m_quanta_count <<"\n";
	cout << " - message passed  :\t" << m_msg_passed_count <<"\n";
	cout << " - thread tables : \n";
	cout << "\t ID \t\t STATUS \t\t MSG_DELIVERED \t\t MSG_TOTAL \t\t PRIORITY \n ";
	threadsTable::iterator iter;
	for(iter = m_tT->begin() ; iter != m_tT->end() ;++iter){
		cout << "\t " << iter->first ;
		cout << "\t\t " << iter->second.status;
		cout << "\t\t " << iter->second.accuMessQua;
		cout << "\t\t\t " << iter->second.totMessQua;
		cout << iter->second.priority << " \n" ;*/
}






